home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Hardware / Mac OS USB DDK / Mac OS USB DDK 1.4.1 / Examples / USBModem / ShimSerialStub.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-25  |  5.4 KB  |  200 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        ShimSerialStub.c
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1998-1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                xxx put dri here xxx
  13.  
  14.         Other Contact:        xxx put other contact here xxx
  15.  
  16.         Technology:            xxx put technology here xxx
  17.  
  18. */
  19.  
  20. #include <Errors.h>
  21. #include <LowMem.h>
  22. #include <TextUtils.h>
  23.  
  24. #include "Modem.h"
  25. #include "ModemVersion.h"
  26. #include "ShimSerialStub.h"
  27.  
  28. //
  29. //    Statically define the Icon & Icon Mask for
  30. //    the CRM structures.  In the new world 
  31. //    (this was Rhapsody) we don't have resources 
  32. //    so we have to do it the hard way.
  33. //    This doesn't make sense anymore we should
  34. //    change this to support resource based icons
  35. //
  36.  
  37. UInt32 CRMDeviceIcon[] = {
  38.     0xFFFFFFFF, 0x80000001, 0x80018001, 0x80018001,
  39.     0x80024001, 0x80042001, 0x80042001, 0x80081001,
  40.     0x800E7001, 0x80024FC1, 0x80C24841, 0x81224841,
  41.     0x82124841, 0x82124CC1, 0x82124501, 0x81224901,
  42.     0x80A25201, 0x80926401, 0x804A0801, 0x80261001,
  43.     0x80102001, 0x80084001, 0x80044001, 0x80024001,
  44.     0x80042001, 0x80081001, 0x80081001, 0x80081001,
  45.     0x80042001, 0x8003C001, 0x80000001, 0xFFFFFFFF,
  46.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  47.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  48.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  49.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  50.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  51.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  52.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  53.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
  54. };
  55.  
  56. /***********************************************************************************/
  57. //    Function:        InstallShimDrvr(CFragConnectionID    ConnID)
  58. //    Description:    Handles the interface with the shim install
  59. //
  60. //    Input:            CFrag Connection ID (mine)
  61. //    Output:            Results
  62. /***********************************************************************************/
  63.  
  64. OSErr InstallShimDrvr(CFragConnectionID    ConnID)
  65. {
  66.     OSErr                 err;
  67.     ShimRefNum            Tref;            // need to do this cause occasionally the globals get lost
  68.                                         // passing the address to the Shim (it switches zones)
  69.     SerialShimInterface    IntBlk;
  70.     
  71.     TraceMessage(0, kCRMName"- Entering InstallShimDrvr");
  72.     
  73.     err = LoadShim();
  74.     if (err == noErr)
  75.     {    
  76.         IntBlk.DRVRInName = kDRVRInName;
  77.         IntBlk.DRVROutName = kDRVROutName;
  78.         IntBlk.CRMName = kCRMName;
  79.         IntBlk.CRMIcon = (IconPtr)&CRMDeviceIcon;
  80.         IntBlk.MaxSpeed = kMaxBaudRate;
  81.         IntBlk.RefCon = 0;
  82.         IntBlk.ConnID = ConnID;
  83.         err = (*gGlobals->ShimInstall) (IntBlk, &Tref);
  84.         gGlobals->ShimRef = Tref;
  85.     }
  86.     
  87.     return err;
  88. }
  89.  
  90. /***********************************************************************************/
  91. //    Function:        RemoveShimDrvr(Boolean forceFlag)
  92. //    Description:    Handles the interface with the shim remove
  93. //
  94. //    Input:            Orderly or forced
  95. //    Output:            Results
  96. /***********************************************************************************/
  97.  
  98. OSErr RemoveShimDrvr(Boolean forceFlag)
  99. {    
  100.     OSErr     err;
  101.     
  102.     TraceMessage(0, kCRMName"- Entering RemoveShimDrvr");
  103.     
  104.     if (gGlobals->ShimRef != kInvalidRef)
  105.     {
  106.         err = (*gGlobals->ShimRemove) (gGlobals->ShimRef, forceFlag);
  107.         if (err == noErr)
  108.             UnLoadShim();
  109.             
  110.         if (err > 0)                // if it's pending the shim handles from here
  111.             err = noErr;            // but we can't unload yet
  112.             
  113.     } else {
  114.         err = -1;
  115.     }
  116.     
  117.     gGlobals->ShimRef = kInvalidRef;
  118.     return err;
  119. }
  120.  
  121. /***********************************************************************************/
  122. //    Function:        LoadShim
  123. //    Description:    Loads the shim and sets up the various addresses
  124. //
  125. //    Input:            Nothing
  126. //    Output:            Results
  127. /***********************************************************************************/
  128.  
  129. OSErr LoadShim(void)
  130. {
  131.     OSErr                err = noErr;            // Let's assume success
  132.     Ptr                    FragAddr;
  133.     CFragConnectionID    ConnID;
  134.     Str255                errMsg;
  135.     CFragSymbolClass    cClass;
  136.     
  137.     err = GetSharedLibrary("\pSerialShimLib", kPowerPCCFragArch, kLoadCFrag, &ConnID, &FragAddr, errMsg);
  138.     if (err == noErr)
  139.     {
  140.         gGlobals->ConnID = ConnID;
  141.         err = FindSymbol(ConnID, "\pSerialShimInstallDriver", (Ptr *)&gGlobals->ShimInstall, &cClass);
  142.         if ((err != noErr) || (cClass != kTVectorCFragSymbol)) 
  143.         {
  144.             err = -1;
  145.         }
  146.         
  147.         if (err == noErr)
  148.         {
  149.             err = FindSymbol(ConnID, "\pSerialShimRemoveDriver", (Ptr *)&gGlobals->ShimRemove, &cClass);
  150.             if ((err != noErr) || (cClass != kTVectorCFragSymbol)) 
  151.             {
  152.                 err = -1;
  153.             }
  154.         }
  155.         
  156.         if (err == noErr)
  157.         {
  158.             err = FindSymbol(ConnID, "\pSerialShimIOComplete", (Ptr *)&gGlobals->ShimComplete, &cClass);
  159.             if ((err != noErr) || (cClass != kTVectorCFragSymbol)) 
  160.             {
  161.                 err = -1;
  162.             }
  163.         }
  164.     }
  165.  
  166.     return err;
  167. }
  168.  
  169. /***********************************************************************************/
  170. //    Function:        UnLoadShim
  171. //    Description:    UnLoads the shim, actually closes the connection
  172. //
  173. //    Input:            Nothing
  174. //    Output:            Results
  175. /***********************************************************************************/
  176.  
  177. OSErr UnLoadShim(void)
  178. {
  179.     OSErr    err = noErr;            // Let's assume success
  180.     
  181.     err = CloseConnection(&gGlobals->ConnID);
  182.     
  183.     return err;
  184.  
  185. }
  186.  
  187. /***********************************************************************************/
  188. //    Function:        ShimIOComplete
  189. //    Description:    Sets up and calls the shim's completion routine
  190. //
  191. //    Input:            Parameter block and result code
  192. //    Output:            nothing
  193. /***********************************************************************************/
  194.  
  195. void     ShimIOComplete(ParmBlkPtr pb, OSErr result)
  196. {
  197.     pb->ioParam.ioResult = result;
  198.     (*gGlobals->ShimComplete) (gGlobals->ShimRef, (IOParam *)pb);
  199.  
  200. }